package com.panopset.gui;


public class ValidatingLongField extends ValidatingField<Long> {
	/**
	 * @param name Name of field, used in validation messages.
	 */
	public ValidatingLongField(final String name) {
		super(name);
	}
	/**
	 * Returns null if not valid.
	 */
	public Long getValue() throws Exception {
		try {
			return Long.parseLong(getTf().getText().replace(",",""));
		} catch (NumberFormatException ex) {
			throw new Exception(getName() + " value " + getTf().getText() + " not a valid integer value.");
		}
	}

	@Override
	public boolean validate(final String s) {
		if (s == null) {
			return false;
		}
		if (s.length() < 1) {
			return false;
		}
		try {
			Long.parseLong(s.replace(",", ""));
		} catch (NumberFormatException nfe) {
			return false;
		}
		return true;
	}

	@Override
	public void save() {
		// TODO Auto-generated method stub
	}

}
